package ihm;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.EmptyBorder;

import dao.DaoEntrainement;

import metier.Entrainement;

@SuppressWarnings("serial")
public class FenetreGestionPlanning extends JFrame implements ActionListener{

	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu mnFichier;
	private JMenuItem mniQuitter;
	private JMenu mnGestion;
	private JMenuItem mniModification;
	private JMenuItem mniSuppression;
	private JButton btnRetour;
	
	private JTable tableauPlannings;
	private Object [][] lignes;
	
	//A VERIFIER AVEC DIAGRAMME UML
	private Vector<Entrainement> lesEntrainements = DaoEntrainement.getLesEntrainements();
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() 
		{
			public void run()
			{
				try
				{
					FenetreGestionPlanning frame = new FenetreGestionPlanning();
					frame.setVisible(true);
				} 
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		});
	}

	//creation du tableau
	public void updateTableau()
	{
		String titres[]={"N° du cours","date","heure de debut","heure de fin"};
		lignes=new Object[lesEntrainements.size()][4];
		int i = 0;
		for (Entrainement unEntr : this.lesEntrainements)
		{
			lignes[i][0] = unEntr.getNum();
	    	lignes[i][1] = unEntr.getDate();
	    	lignes[i][2] = unEntr.getHeureDeb();
	    	lignes[i][3] = unEntr.getHeureFin();

		   	i++;
		}
		this.tableauPlannings = new JTable(lignes,titres);
	}
	
	
	/**
	 * Create the frame.
	 */
	public FenetreGestionPlanning() 
	{
		setBounds(100, 100, 450, 300);
		// ---- MENU ---
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		// --- MENU FICHIER ---
		mnFichier = new JMenu("Fichier");
		menuBar.add(mnFichier);
		
		mniQuitter = new JMenuItem("Quitter");
		mniQuitter.addActionListener(this);
		menuBar.add(mnFichier);
		
		mnFichier.add(mniQuitter);
		
		// --- MENU GESTION ---
		mnGestion = new JMenu("Gestion");
		menuBar.add(mnGestion);
				
		mniModification = new JMenuItem("Modification");
		mnGestion.add(mniModification);
		
		mniSuppression = new JMenuItem("Suppression");
		mnGestion.add(mniSuppression);
		// END MENU
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblPlanning = new JLabel("Planning");
		lblPlanning.setBounds(161, 11, 100, 14);
		contentPane.add(lblPlanning);
		
		/*JButton btnModifier = new JButton("Modifier");
		btnModifier.setBounds(29, 213, 90, 20);
		contentPane.add(btnModifier);
		
		JButton btnEnregistrer = new JButton("Enregistrer");
		btnEnregistrer.setBounds(161, 213, 105, 20);
		contentPane.add(btnEnregistrer);*/
		
		btnRetour = new JButton("Retour");
		btnRetour.addActionListener(this);
		btnRetour.setBounds(304, 213, 90, 20);
		contentPane.add(btnRetour);
		
		this.tableauPlannings = new JTable();
		this.tableauPlannings.setBounds(100, 400, 405, 190);
		
		updateTableau();
		JScrollPane scrollPane = new JScrollPane(tableauPlannings,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		scrollPane.setBounds(20, 30
				, 405, 170);
		contentPane.add(scrollPane);
		
		
	}
	
	@Override
	public void actionPerformed(ActionEvent evt)
	{
		if(evt.getSource() == btnRetour)
			this.dispose();
		
		
	}
}

	
	
	